<?php
/**
 * Galdic project
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Galdic
 * @package    Galdic
 * @copyright  Copyright (c) 2009 vifito (http://vifito.eu)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

/**
 * Service_RagController
 * 
 * @package    Galdic
 * @copyright  Copyright (c) 2009 vifito (http://vifito.eu)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: RagController.php 1 2009-09-15 00:39:16Z vifito $
 */
class Service_RagController extends Zend_Controller_Action
{

    public function init()
    {
        $layout = Zend_Layout::getMvcInstance();        
        $layout->disableLayout();
        
        $this->getHelper('viewRenderer')->setNoRender();
        
        $this->server = new Zend_Json_Server();
        $this->server->setClass('Service_Model_RagDic');        
    }

    public function indexAction()
    {
        $this->queryAction();
    }

    public function queryAction()
    {
        if ('GET' == $_SERVER['REQUEST_METHOD']) {
            $this->_discoverService();
        }
        
        $this->server->handle();
    }

    private function _discoverService()
    {
        // Indicate the URL endpoint, and the JSON-RPC version used:        
        $this->server->setTarget('/service/rag')
               ->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2);
        
        // Grab the SMD
        $smd = $this->server->getServiceMap();
        //$smd->setDojoCompatible(true);
        
        // Return the SMD to the client
        header('Content-Type: application/json');
        echo $smd;
        return;        
    }
}





